const detailDataPkg = (origin, uid, vipLevel, ua) => {

    return co(function*() {
        let result = {}; // 结果输出

        // 商品名称
        if (!origin.productName) {
            return result;
        }

        origin.uid = uid;
        result.name = origin.productName;
        result.skn = origin.erpProductId;
        result.productId = origin.id;
        result.maxSortId = origin.maxSortId;
        result.smallSortId = origin.smallSortId;
        result.promotionId = origin.isPromotion;
        result.goCartUrl = helpers.urlFormat('/shopping/cart');

        // 接口处理数据，设置并发请求数据
        yield setMultiResourceByProductBaseInfo(origin);

        let brandId = 0;

        if (origin.brand.id) {
            brandId = origin.brand.id;
        }

        // 处理收藏喜欢数据
        let favoriteData = yield getProductFavoriteData(uid, result.productId, brandId);

        // 商品标签
        result.tags = getTagsDataByProductInfo(origin);

        //  商品促销短语
        if (origin.salesPhase) {
            result.saleTip = origin.salesPhrase;
        }

        // 商品价格
        if (origin.productPriceBo) {
            result.marketPrice = origin.productPriceBo.formatMarketPrice;
            result.hasOtherPrice = true;
            result.salePrice = origin.productPriceBo.formatSalesPrice;
            if (result.marketPrice === result.salePrice) {
                delete result.salePrice;
                result.hasOtherPrice = false;
            }
        }

        //  VIP数据
        result.vipPrice = getVipDataByProductBaseInfo(origin, vipLevel, uid);

        //  促销活动banner
        result.activity = yield getActivityDataByProductBaseInfo(origin);

        const C_VALUE = {
            type: '返YOHO币',
            des: '每件返 ',
            rest: '个 YOHO币'
        };

        if (origin.productPriceBo.yohoCoinNum && origin.productPriceBo.yohoCoinNum !== 0) {
            result.activity.push({
                type: C_VALUE.type,
                des: `${C_VALUE.des}${origin.productPriceBo.yohoCoinNum}${C_VALUE.rest}`
            });
        }

        // 上市期
        if (origin.expectArrivalTime) {
            result.arrivalDate = `${origin.expectArrivalTime}月`;
            result.presalePrice = origin.productPriceBo.formatSalesPrice;
            delete result.salePrice;
            result.hasOtherPrice = false;
        }

        // 商品咨询和评论数据，当前为空
        let consultComment = getConsultCommentDataByProductInfo(origin);

        // 品牌信息
        let banner = null;

        if (origin.brand) {
            result.brandImg = helpers.image(origin.brand.brandIco, 47, 47);
            result.brandName = origin.brand.brandName;
            result.brandUrl = helpers.urlFormat('', {}, origin.brand.brandDomain);
            banner = yield getBrandDataByProductBaseInfo(origin);
            if (banner.isCollect && favoriteData.brand) {
                banner.isCollect = favoriteData.brand;
            }
        }

        // sku商品信息
        let skuData = getSkuDataByProductBaseInfo(origin);

        result.img = skuData.defaultImage;
        result.colors = skuData.skuGoods;
        let totalStorageNum = skuData.totalStorageNum;

        // 是否收藏
        result.isCollect = favoriteData.product;

        if (origin.isLimitBuy === 'y') {
            // 是否开售
            let isBeginSale = !!(origin.saleStatus && origin.saleStatus === 1);

            // 限购商品有关的展示状态
            let showStatus = 1;

            if (origin.showStatus) {
                showStatus = parseInt(origin.showStatus);
            }

            let fashTopGoods = getFashionTopGoodsStatus(uid, showStatus, isBeginSale);


            result.fashTopGoods = {
                getLimitedCode: fashTopGoods.getLimitedCode, // 限购码状态
                hasLimitedCode: fashTopGoods.hasLimitedCode, // 是否已经获取限购码
                limitedCodeSoldOut: fashTopGoods.limitedCodeSoldOut, // 限购码是否已经抢光
                getLimitedCodeDis: fashTopGoods.getLimitedCodeDis // 限购码是否失效
            };

            if (fashTopGoods.soldOut) {
                result.soldOut = fashTopGoods.soldOut;
                totalStorageNum = 0; // 改总数为已售磬
            } else {
                result.openSoon = fashTopGoods.openSoon; // 即将开售
                result.dis = fashTopGoods.dis; // 是否失效
                result.buyNow = fashTopGoods.buyNow; // 是否立即购买
            }
        }

        let soldOut = !!(origin.status === 0 || totalStorageNum === 0);

        let notForSale = origin.attribute === 2; // 非卖品

        let virtualGoods = origin.attribute === 3; // 虚拟商品

        if (!soldOut && !notForSale && !virtualGoods) {
            result.addToCart = true;

            // 立即购买或者即将开售存在
            if (result.buyNow || result.openSoon) {
                delete result.addToCart;
            }
        } else if (notForSale) {
            // 非卖品
            result.notForSale = true;
        } else if (soldOut) {
            // 已售磬
            result.soldOut = true;
            delete result.fashTopGoods;
        } else if (virtualGoods) {
            // 虚拟商品
            result.buyNow = true; // 是否立即购买
            result.buyNowBase = helpers.urlFormat('/ticket', {}, 'shopping');
            result.virtualGoods = virtualGoods;
            if (result.salePrice) {
                result.advancePrice = result.salePrice; // 先行价格
                delete result.salePrice;
            }
        }

        // 去掉即将售罄
        if (totalStorageNum || soldOut) {
            if (result.tags.isFew) {
                delete result.tags.isFew; // 去掉即将售罄
            }
        }

        // 分享相关，产品的链接
        result.weixinUrl = helpers.urlFormat(origin.productUrl, {}, 'item');
        result.shareTitle = result.name;
        result.shareImg = result.img;
        result.shareDesc = result.phrase;


        // 统计需要的商品信息
        let statGoodsInfo = {};

        statGoodsInfo.uid = uid;
        statGoodsInfo.skn = origin.erpProductId;
        statGoodsInfo.productId = origin.id;
        statGoodsInfo.productName = result.name.replace('\'', '’');
        statGoodsInfo.brandName = (result.brandName || '').replace('\'', '’');
        statGoodsInfo.marketPrice = result.marketPrice.replace('¥', '');
        if (result.salePrice) {
            statGoodsInfo.salePrice = result.salePrice.replace('¥', '');
        } else {
            statGoodsInfo.salePrice = result.marketPrice.replace('¥', '');
        }

        if (banner.brandId) {
            let domainBrand = yield BrandData.getBrandByDomainAsync(banner.brandDomain);

            if (domainBrand.type && domainBrand.shopId) {
                switch (parseInt(domainBrand.type)) {
                    case 1:
                        {
                        // 多品店不显示
                            banner = [];
                            break;
                        }
                    case 2:
                        {
                        // TODO:单品店显示新版的店铺banner,item.php 210
                            let basisData = ShopModel.basisTemplate(domainBrand.shopId);

                            banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
                            break;
                        }

                }
            }
        }

        statGoodsInfo.imageUrl = result.img;
        statGoodsInfo.productUrl = result.weixinUrl;
        statGoodsInfo.smallSortId = result.smallSortId;
        statGoodsInfo.soldOut = parseInt(soldOut);

        return {
            goodsInfo: result,
            consultComment: consultComment,
            banner: banner,
            statGoodsInfo: statGoodsInfo
        };
    })();
};